package ynu.edu.controller;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import ynu.edu.common.controller.LogicController;
import ynu.edu.dao.*;
import ynu.edu.entity.*;
import ynu.edu.service.CustomerService;


@Api(tags = "客户实体的控制器")
@RestController
@RequestMapping("/customer")
public class CustomerController extends LogicController<CustomerService, CustomerDao, Customer,Long> {
    public CustomerController(@Autowired CustomerService service){
        super(service);
    }
    @PostMapping("/cancelOrder")
    public Order1 cancelOrder(@RequestParam("name")String name, @RequestParam("orderId")Long orderId){
        return getService().cancelOrder(name,orderId);
    }
    @PostMapping("/fund")
    public Order1 fundOrder(@RequestParam("name")String name, @RequestParam("orderId")Long orderId){
        return getService().fundOrder(name,orderId);
    }
    @GetMapping("/getAllMyOrder")
    public List<Order1> getAllMyOrder(@RequestParam("name")String name){
        return getService().getAllMyOrder(name);
    }
    @PostMapping("/createOrder")
    public Order1 createOrder(@RequestParam("name")String name,@RequestParam("shopId")Long shopId,
                              @RequestParam("shopItemId")Long shopItemId,@RequestParam("amount")Integer amount){
        return getService().createOrder(name, shopId, shopItemId, amount);
    }
    @GetMapping("/getUnFundOrder")
    public Order1 getUnFundOrder(@RequestParam("name")String name,@RequestParam("shopId")Long shopId){
        return getService().findUnFundOrderByShop(name,shopId);
    }
    @PostMapping("/login")
    public Customer login(@RequestParam("name")String name, @RequestParam("password")String password){
        return getService().login(name,password);
    }
    @PostMapping("/register")
    public Customer register(@RequestParam("name")String name,@RequestParam("password")String password){
        System.out.println(name);
        return getService().register(name,password);
    }
}

